package com.lxmes.gs.controller;

import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import com.lxmes.gs.domain.taskProgressVO.*;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.gs.domain.TaskProgress;
import com.lxmes.gs.service.ITaskProgressService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 任务进度Controller
 * 
 * @author wdf
 * @date 2023-04-24
 */
@Api(tags = "任务进度")    
@RestController
@RequestMapping("/gs/taskProgress")
public class TaskProgressController extends BaseController{
    @Autowired
    private ITaskProgressService taskProgressService;

    /**
     * 查询任务进度列表
     */
    @ApiOperation("查询任务进度列表")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskProgressSearchVO taskProgress){
        startPage();
        List<TaskProgress> list = taskProgressService.selectTaskProgressList(BeanUtil.copyProperties(taskProgress,TaskProgress.class));
        return getDataTable(Convert.convert(new TypeReference<List<TaskProgressResultVO>>() {},list));
}

    /**
     * 导出任务进度列表
     */
    @ApiOperation("导出任务进度列表")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:export')")
    @Log(title = "任务进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskProgress taskProgress){
        List<TaskProgress> list = taskProgressService.selectTaskProgressList(taskProgress);
        List<TaskProgressExportVO> exportList = Convert.convert(new TypeReference<List<TaskProgressExportVO>>() {}, list);
        ExcelUtil<TaskProgressExportVO> util = new ExcelUtil<TaskProgressExportVO>(TaskProgressExportVO.class);
        util.exportExcel(response, exportList, "任务进度数据");
    }

    /**
     * 获取任务进度详细信息
     */
    @ApiOperation("获取任务进度详细信息")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(taskProgressService.selectTaskProgressById(id));
    }

    /**
     * 新增任务进度
     */
    @ApiOperation("新增任务进度")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:add')")
    @Log(title = "任务进度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskProgressCreateVO taskProgress){
        return toAjax(taskProgressService.insertTaskProgress(BeanUtil.copyProperties(taskProgress,TaskProgress.class)));
    }

    /**
     * 修改任务进度
     */
    @ApiOperation("修改任务进度")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:edit')")
    @Log(title = "任务进度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskProgressUpdateVO taskProgress){
        return toAjax(taskProgressService.updateTaskProgress(BeanUtil.copyProperties(taskProgress,TaskProgress.class)));
    }

    /**
     * 删除任务进度
     */
    @ApiOperation("删除任务进度")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:remove')")
    @Log(title = "任务进度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(taskProgressService.deleteTaskProgressByIds(ids));
    }
    
    /**
     * 任务进度统计审核
     */
    @ApiOperation("任务进度统计审核")
    @PreAuthorize("@ss.hasPermi('gs:taskProgress:audit')")
    @Log(title = "任务进度统计审核")
	@PostMapping("/auditTaskProgress/{ids}")
    public AjaxResult auditTaskProgress(@PathVariable Long[] ids){
        return toAjax(taskProgressService.auditTaskProgress(ids));
    }
    /**
     * 导入任务进度
     */
    @Log(title = "任务进度", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception{
        ExcelUtil<TaskProgressImportVO> util = new ExcelUtil<>(TaskProgressImportVO.class);
        List<TaskProgressImportVO> taskProgressList = util.importExcel(file.getInputStream());
        String message = taskProgressService.imporIteminfo(Convert.convert(new TypeReference<List<TaskProgress>>() {},taskProgressList), updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException{
        ExcelUtil<TaskProgressImportVO> util = new ExcelUtil<>(TaskProgressImportVO.class);
        util.importTemplateExcel(response,"任务进度");
    }
}
